Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.batch5.day1.q1;
- import java.util.Scanner;
- public class Fibonacci
- {
- public static void main(String st[])
- {
- float sum=0;
- int number1=1;
- int number2=1;
- int number3;
- sum=number1+number2;
- Scanner sc=new Scanner(System.in);
- System.out.println("Enter size of fibonacci");
- int size=sc.nextInt();
- System.out.print(number1+" "+number2);
- for(int i=2;i<size;i++)
- {
- number3=number1+number2;
- sum=sum+number3;
- System.out.print(" "+number3);
- number1=number2;
- number2=number3;
- }
- sc.close();
- System.out.println();
- System.out.println("The average is: "+(sum/20));
- }
- }
- 1-2
- package com.batch5.day1.q2;
- public class TimeTable
- {
- void multiply()
- {
- System.out.println("*|1 2 3 4 5 6 7 8 9");
- System.out.println("--------------------------");
- for(int i=1;i<=9;i++)
- {
- System.out.print(i+"|");
- for(int j=1;j<=9;j++)
- {
- System.out.print(i*j+" ");
- }
- System.out.println();
- }
- }
- }
- 1-3
- package com.batch5.day1.q3;
- import java.util.Scanner;
- public class GradeAverage {
- public static void main(String st[])
- {
- Scanner sc=new Scanner(System.in);
- int noOfStudents;
- float sumOfGrade=0;
- System.out.print("Enter the number of students: ");
- noOfStudents=sc.nextInt();
- System.out.println();
- int grades[]=new int[noOfStudents+1];
- for(int i=1;i<=noOfStudents;i++)
- {
- System.out.print("Enter the grade of student "+i+": ");
- grades[i]=sc.nextInt();
- System.out.println();
- if(grades[i]<0||grades[i]>100)
- {
- System.out.println("Enter valid input");
- System.out.println("Enter the grade of student "+i+": ");
- grades[i]=sc.nextInt();
- sumOfGrade+=grades[i];
- }
- else
- {
- sumOfGrade+=grades[i];
- }
- }
- sc.close();
- System.out.println("The average is: "+(sumOfGrade/noOfStudents));
- }
- }
- 1-4
- package com.batch5.day1.q4;
- import java.util.Scanner;
- public class ArrayCopy {
- public static int[] copyOf(int[] array)
- {
- return array;
- }
- public static void main(String st[])
- {
- int arr[]=new int[10];
- Scanner sc=new Scanner(System.in);
- System.out.println("Enter size of array(max 10)");
- int size=sc.nextInt();
- System.out.println("Enter the elements)");
- for(int i=0;i<size;i++)
- {
- arr[i]=sc.nextInt();
- }
- int copy[]=copyOf(arr);
- System.out.println("Copied Array: ");
- for(int i=0;i<size;i++)
- {
- System.out.println(copy[i]);
- }
- sc.close();
- }
- }
- 1-5
- package com.batch5.day1.q5;
- public class Pattern {
- public static void main(String st[])
- {
- for(int i=1;i<=8;i++)
- {
- for(int j=1;j<=i;j++)
- {
- System.out.print(j);
- }
- System.out.println();
- }
- }
- }
Add Comment
Please, Sign In to add comment