Skip to main content

Posts

Showing posts from July, 2014

Netbeans_codes.png

Get Prime Numbers - Netbeans Java Codes

Run-Shot of Prime Numbers Java Code: import java.util.Scanner; public class FirstnPrimeNumbers { public static void main(String args[]) { Scanner ObjPrime = new Scanner(System.in); int n; System.out.println("Enter the number of prime numbers required."); n=ObjPrime.nextInt(); int k =1; int i,noPrime=0; int num =2 ; do{ for(i=2;i<num;i++){ if(num%i==0) noPrime++; } i=2; if(noPrime==0){ System.out.println("Prime number "+k+" is "+num); k++; } noPrime=0; num++; }while(k<=n); } } [Find more Netbeans Java Code at www.sumikuma.tk] You can also download text file version of this code: Prime-Numbers_javacode.txt

Get Pascal's Triangle - Netbeans Java Codes

Run-Shot of Pascal's Triangle Java Code: public class Pascalstriangle { public static void main(String args[]) { int x = 6; int triangle[][] = new int[x][x]; for (int i = 0; i < x; i++) { for (int j = 0; j < x; j++) { triangle[i][j] = 0; } } for(int i = 0; i < x; i++) { triangle[i][0] = 1 ; } for (int i = 1; i < x; i++) { for (int j = 1; j < x; j++) { triangle[i][j] = triangle[i-1][j-1] + triangle[i-1][j]; } } for (int i = 0; i < x; i++) { for(int j=0;j<=i;j++) { System.out.print(triangle[i][j]+ " "); } System.out.println(); } } } [Find more Netbeans Java Code at www.sumikuma.tk] You can also download text file version of this code: Pascal-triangle_javacode.txt

Image Viewer - Netbeans Java Codes

Run-Shot of Image Viewer displaying sumikuma logo Java Code: import java.awt.BorderLayout; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import static javax.swing.JOptionPane.INFORMATION_MESSAGE; import static javax.swing.JOptionPane.WARNING_MESSAGE; import static javax.swing.JOptionPane.showMessageDialog; import javax.swing.JScrollPane; import javax.swing.KeyStroke; /** * * [Find more Netbeans Java Code at www.sumikuma.tk] */ public class ImageViewer implements ActionListener { private BufferedImage image; private JFra

Find Greatest Number Out of 3 Numbers - Netbeans Java Codes

Run-Shot of Greatest Number Out of  3 Numbers Java Code: import java.util.Scanner; public class GreatestOfAll { public static void main(String args[]){ Scanner ObjGreat = new Scanner(System.in); int a=0,b=0,i; for(i=1;i<=3;i++){ System.out.println("Enter a number"); if(i==1) a=ObjGreat.nextInt(); else b=ObjGreat.nextInt(); if(b>a) a=b; } System.out.println("Greatest number = "+a); } } [Find more Netbeans Java Code at www.sumikuma.tk] You can also download text file version of this code: GreatestNumber_javacode.txt

Print Fibonacci Series - Netbeans Java Code

Run-Shot of Fibonacci Series Java Code: [Find more Netbeans Java Code at www.sumikuma.tk] public class Fibonacciseries { public static void main(String args[]) { int prev, next, sum, n; prev=next=1; for(n=1;n<=11;n++) { System.out.println(prev); sum=prev+next; prev=next; next=sum; } } } [Find more Netbeans Java Code at www.sumikuma.tk] You can also download text file version of this code: FibonacciSeries_JavaCode.txt

Find Factorial -Netbeans Java Code

Run Shot of An Integer to Calculate its factorial Java Code: import java.util.Scanner; public class Factorial { public static void main(String args[]) { int n, c, fact = 1; System.out.println("Enter an integer to calculate it's factorial"); Scanner in = new Scanner(System.in); n = in.nextInt(); if ( n < 0 ) System.out.println("Number should be non-negative."); else { for ( c = 1 ; c <= n ; c++ ) fact = fact*c; System.out.println("Factorial of "+n+" is = "+fact); } } } Find more netbeans java code from www.sumikuma.tk You can also download text file version of this code: Factorial.txt

Digital Clock - Netbeans Java Code

Run-Shot of Digital Clock Java Code: import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.SimpleDateFormat; import java.util.Date; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.Timer; public class DigitalClock extends JLabel { private String pattern; private Timer timer; private int delay; /** * Constructs a Digital Clock using the given pattern and the default delay. * @param pattern - the pattern describing the date and time format */ public DigitalClock(String pattern){ this.pattern = pattern; this.delay = 1000; createTimer(); timer.start(); } /** * Constructs a Digital Clock using the given pattern and delay. * @param delay - the number of milliseconds between action events * @param pattern - the pattern describing the date and time format */ public DigitalClock(String pattern, int delay){ this.pattern = pattern; this.d

Get Current System Time & Date - Netbeans Java Code

Run Shot of Current System Time & Date Java Code: import java.text.SimpleDateFormat; import java.util.Date; public class Datetimemonth { public static void main(String[] args) { Date now = new Date(); System.out.println("toString(): " + now); // dow mon dd hh:mm:ss zzz yyyy // SimpleDateFormat can be used to control the date/time display format: // E (day of week): 3E or fewer (in text xxx), >3E (in full text) // M (month): M (in number), MM (in number with leading zero) // 3M: (in text xxx), >3M: (in full text full) // h (hour): h, hh (with leading zero) // m (minute) // s (second) // a (AM/PM) // H (hour in 0 to 23) // z (time zone) SimpleDateFormat dateFormatter = new SimpleDateFormat("E, y-M-d 'at' h:m:s a z"); System.out.println("Format 1: " + dateFormatter.format(now)); dateFormatter = new Sim

Calculator - Netbeans Java Code

Run Shot of Calculator Java Code: public class Calculator { public static void main(String[] args) { boolean go = true; //sets up loop while(go) //creates loop to top { System.out.println("Hello this is my calculator!"); System.out.println("To add, type a, to subtract, type s."); System.out.println("To multiply, type m, to divide, type d."); Scanner scan = new Scanner(System.in); //sets up scanners Scanner scan1 = new Scanner(System.in); String action = scan.nextLine(); //tells comp. to take user input if("a".equals(action)) //addition { System.out.println("Now type in the first number you would like to add."); int add1 = scan.nextInt(); System.out.println("Now type the second number."); int add2 = scan.nextInt();

Arithmetic Progression - Netbeans Java Code

Run-Shot: Java Code: public class Arithmeticprogression { public static void main(String[] args) { int d; double x; int n; double s; int i; int v; double z; Scanner console=new Scanner(System.in); System.out.print("Enter the Common difference: "); d=console.nextInt(); System.out.print("Enter the First Term: "); x=console.nextDouble(); System.out.print("Enter the Number of Terms: "); n=console.nextInt(); for(i=0,s=0;n>i;i++){ System.out.println(""+(x+(i*d))); s=s+(x+(i*d)); } System.out.println(""); System.out.println("The sum is "+s); } } You can also download the text file of this code here: ArithmeticProgresssion-javacode.txt