Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!

# rose khf

Greenhorn
since Sep 23, 2013
Cows and Likes
Cows
0
In last 30 days
0
Total given
0
Likes
0
0
Total given
0
Given in last 30 days
0
Scavenger Hunt Ranch Hand Scavenger Hunt Greenhorn Scavenger Hunt

## Recent posts by rose khf

fred rosenberger wrote:

rose khf wrote:then how I can found largest sum of primes in diagonal ???

How would you do it with pencil and paper?

I don't know you have to tell me otherwise why I put the question
6 years ago
here is first step which is to cheak if number is prime or not using if statement [package primespiral;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class Primespiral {

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException {
Scanner infile = new Scanner(new FileReader("spiral.in"));
PrintWriter outfile = new PrintWriter("spiral.out");
//define limit
int size = 100;

//loop through the numbers one by one
for (int i = 0; i < 100; i++) {
boolean isPrime = true;
//check to see if the number is prime
for (int j = 2; j < i; j++) {
if (i % j == 0) {
isPrime = false;
break;
}
}
// print the number
if (isPrime) {
outfile.print(i + " ");
}
}

}
}

]

then how I can found largest sum of primes in diagonal ???
6 years ago
Hi there

iam new member in this website and my first topic

I have question in prime spiral
here is question :
Write a JAVA program that takes one or more values for N on the command line
where N is always an odd number in the range 0 < N < 100.
For each N, your program must determine the largest sum of primes along any
diagonal straight line in a grid of size NxN. Write the answer on a separate line,
in the form:
N: S
where N is the grid size, S is the largest sum. For example, given 3 and 5 on the
command line, your program should print:
3: 10
5: 49

also it has two files "spiral.in" which contain input (2,3,5),and "spiral.out" (49,10)
how I can write code for this question ???
plzz help me
6 years ago