Posts

Showing posts from April, 2019

Iterate

Iterate with LinkList class GFG {     public static void bfs(int s, ArrayList<Integer> adj[],boolean visited[])     {         visited[s]=true;         LinkedList<Integer> queue=new LinkedList<>();         queue.add(s);         while(!queue.isEmpty())         {             int temp=queue.poll();             System.out.print(temp+" ");              Iterator<Integer> ir=adj[temp].listIterator();             while(ir.hasNext())             {       ...

java for interview

Image
Java has 8 primitive data types : byte , boolean , char , double, short , int , long , float , Scanner Yesterday, we discussed Scanner's next , nextLine , hasNext , and hasNextLine methods Additive Operator The + operator is used for mathematical addition and String concatenation (i.e.: combining two Strings into one new String). If you add the contents of two variables together (e.g.: a + b ),….. System.out.println(a + b); c++ // eat whitespace getline(cin >> ws, s2); #include <iostream> #include <iomanip> using namespace std; int main(int argc, char *argv[]) {   double pi = 3.14159;       // Let's say we wanted to scale this to 2 decimal places:   cout << fixed << setprecision(2) << pi << endl;   printf("%.2f", pi); } which produces this output: 3.14 3.14 This is a common problem, and it happens because the nextInt method doesn't ...