Click here to Skip to main content
14,982,680 members
Home / Discussions / Java
   

Java

 
Questionjava applet programm Pin
mohit gite12-Nov-18 22:40
Membermohit gite12-Nov-18 22:40 
QuestionRe: java applet programm Pin
Richard MacCutchan13-Nov-18 5:08
mveRichard MacCutchan13-Nov-18 5:08 
QuestionFirst Android App Pin
C-P-User-311-Nov-18 21:30
MemberC-P-User-311-Nov-18 21:30 
AnswerRe: First Android App Pin
Richard MacCutchan11-Nov-18 22:02
mveRichard MacCutchan11-Nov-18 22:02 
GeneralRe: First Android App Pin
C-P-User-313-Nov-18 20:14
MemberC-P-User-313-Nov-18 20:14 
Questionjava Pin
Member 1404304811-Nov-18 1:07
MemberMember 1404304811-Nov-18 1:07 
AnswerRe: java Pin
Richard MacCutchan11-Nov-18 2:31
mveRichard MacCutchan11-Nov-18 2:31 
QuestionScala Code Review Pin
traubad10-Nov-18 12:46
Membertraubad10-Nov-18 12:46 
Hey all, I'm not sure where to post this but I hope it's ok to throw it in here. I'm currently learning Scala and I come from more of a Java, C++, Python background. I wrote some code just to sort of figure some stuff out and experiment a bit. I'd love some some feedback, particularly regarding technique and convention and whatnot. The following code will run. I'm doing some simple lazy evaluation of primes. Thanks again.

import scala.collection.mutable.MutableList
import scala.collection.Iterable
import scala.io.{StdIn => input}

object Main {
  
  def main(args: Array[String]): Unit = {
    var primeList = MutableList[Int]()
    var primeFinder = Iterator.from(2)
    nPrimes(primeFinder, primeList)
    //oneAtATime(primeFinder,primeList)
  }
  
  def oneAtATime(primeFinder: Iterator[Int], primeList: MutableList[Int]): Unit = {
    println("We are lazily finding all the primes!")
    do {
      nextPrime(primeFinder,primeList)
      println("So far, we have: " + primeList.mkString("[",",","]"))
      println("Continue?(press n to quit): ")          
    } while (input.readLine().toLowerCase() != "n")    
  }
  
  def nPrimes(primeFinder: Iterator[Int], primeList: MutableList[Int]): Unit = {
    println("How many primes would you like to find? ")
    val totalPrimes = input.readInt()
    for( i <- 1 to totalPrimes) nextPrime(primeFinder, primeList)
    println("First "+totalPrimes+" primes: " + primeList.mkString("[",",","]"))
  }
  
  def nextPrime(primeFinder: Iterator[Int], primeList: MutableList[Int]): Unit = {
    var isPrime = (n: Int, primes: Iterable[Int]) => (primes.takeWhile(p => p*p <= n).forall(n % _ != 0))
    var primeVal = primeFinder.next()
    while (!isPrime(primeVal,primeList)) primeVal = primeFinder.next()    
    primeList += primeVal      
  }    
}

AnswerRe: Scala Code Review Pin
Richard MacCutchan10-Nov-18 21:07
mveRichard MacCutchan10-Nov-18 21:07 
Questionduplicate elmente in Array multiply Pin
Nasif228-Nov-18 13:08
MemberNasif228-Nov-18 13:08 
Questionjava Pin
Member 140430484-Nov-18 23:51
MemberMember 140430484-Nov-18 23:51 
AnswerRe: java Pin
Richard MacCutchan5-Nov-18 5:17
mveRichard MacCutchan5-Nov-18 5:17 
AnswerRe: java Pin
mohit gite16-Nov-18 21:25
Membermohit gite16-Nov-18 21:25 
AnswerRe: java Pin
GiteHrudaya28-Nov-18 18:48
MemberGiteHrudaya28-Nov-18 18:48 
AnswerRe: java Pin
GiteHrudaya2-Dec-18 22:59
MemberGiteHrudaya2-Dec-18 22:59 
Questionjava Pin
mohit gite4-Nov-18 21:45
Membermohit gite4-Nov-18 21:45 
AnswerRe: java Pin
Richard MacCutchan4-Nov-18 23:05
mveRichard MacCutchan4-Nov-18 23:05 
AnswerRe: java Pin
GiteHrudaya29-Nov-18 23:13
MemberGiteHrudaya29-Nov-18 23:13 
Questionjava Pin
Member 140430483-Nov-18 21:03
MemberMember 140430483-Nov-18 21:03 
AnswerRe: java Pin
Richard MacCutchan3-Nov-18 21:25
mveRichard MacCutchan3-Nov-18 21:25 
GeneralRe: java Pin
Member 140430483-Nov-18 21:38
MemberMember 140430483-Nov-18 21:38 
GeneralRe: java Pin
Richard MacCutchan3-Nov-18 22:17
mveRichard MacCutchan3-Nov-18 22:17 
GeneralRe: java Pin
Member 140430483-Nov-18 22:25
MemberMember 140430483-Nov-18 22:25 
GeneralRe: java Pin
Richard MacCutchan3-Nov-18 22:32
mveRichard MacCutchan3-Nov-18 22:32 
GeneralRe: java Pin
Member 140430483-Nov-18 23:02
MemberMember 140430483-Nov-18 23:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.